package com.zjj.edu.system.service.impl;

import com.zjj.edu.common.constant.UserConstants;
import com.zjj.edu.common.utils.DateUtils;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.system.domain.SysGrade;
import com.zjj.edu.system.mapper.SysGradeMapper;
import com.zjj.edu.system.service.ISysGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 年级Service业务层处理
 *
 * @author zjj
 * @date 2020-06-02
 */
@Service
public class SysGradeServiceImpl implements ISysGradeService
{
    @Autowired
    private SysGradeMapper sysGradeMapper;

    /**
     * 查询年级
     *
     * @param id 年级ID
     * @return 年级
     */
    @Override
    public SysGrade selectSysGradeById(Long id)
    {
        return sysGradeMapper.selectSysGradeById(id);
    }

    /**
     * 查询年级列表
     *
     * @param sysGrade 年级
     * @return 年级
     */
    @Override
    public List<SysGrade> selectSysGradeList(SysGrade sysGrade)
    {
        return sysGradeMapper.selectSysGradeList(sysGrade);
    }

    /**
     * 新增年级
     *
     * @param sysGrade 年级
     * @return 结果
     */
    @Override
    public int insertSysGrade(SysGrade sysGrade)
    {
        sysGrade.setCreateTime(DateUtils.getNowDate());
        return sysGradeMapper.insertSysGrade(sysGrade);
    }

    /**
     * 修改年级
     *
     * @param sysGrade 年级
     * @return 结果
     */
    @Override
    public int updateSysGrade(SysGrade sysGrade)
    {
        sysGrade.setUpdateTime(DateUtils.getNowDate());
        return sysGradeMapper.updateSysGrade(sysGrade);
    }

    /**
     * 删除年级对象
     *
     * @return 结果
     */
    @Override
    public int deleteSysGradeByIds(SysGrade sysGrade)
    {
        return sysGradeMapper.deleteSysGradeByIds(sysGrade);
    }

    @Override
    public String checkNameUnique(SysGrade vo) {
        Long id = StringUtils.isNull(vo.getId()) ? -1L : vo.getId();
        SysGrade info = sysGradeMapper.checkNameUnique(vo.getName(), vo.getTenantId());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return UserConstants.NAME_NOT_UNIQUE;
        }
        return UserConstants.NAME_UNIQUE;
    }

    @Override
    public List<SysGrade> selectAllSysGradeList(long tenantId) {
        return sysGradeMapper.selectAllSysGradeList(tenantId);
    }
}
